The traditional functional-oriented approach to programming has largely been superseded by the object-oriented programming paradigm. With functional-oriented programming, code is organized around actions and written based primarily on logic. With object-oriented programming, code is organized around “objects” and written responsive primarily to the underlying data.
Object-oriented programming provides many conceptual advances and code-related benefits such as reusability, adaptability, modularity, and so forth. These benefits arise, at least partly, from the fundamental tenets of object-oriented programming and the principles that flow therefrom. For example, object-oriented programming usually adheres to encapsulation, inheritance, and polymorphism.
Encapsulation relates to the ability and tendency of an object to protect its data by limiting access to its data from external sources. A given object can stipulate which of its data are exposed and can constrain if not fully control how its data may be manipulated.
Inheritance enables characteristics of one class of objects to be extended to another class. For example, each sub-class of a super-class inherits all of the characteristics of that super-class. Furthermore, a programmer may specify which additional characteristics are to be newly included for each inheriting sub-class. A resulting set of inheritance relationships is carefully crafted by the compiler at compile time. A hierarchical framework that facilitates extensions of existing classes is thereby enabled with inheritance.
Polymorphism may refer, at least partly, to an ability of an object to react differently to different stimulus. In other words, polymorphism may pertain to being able to assign a different usage or meaning to the same information in different contexts. More specifically, traditional polymorphism enables the programmed procedures of super-classes to be redefined for their corresponding sub-classes. However, this redefining ability is limited. Such redefinitions for the programmed procedures are fixed at compile time. In fact, a programmer or designer establishes the potential polymorphism based on expectations and/or predictions for the likely inputs of the programmed procedures.
Furthermore, traditional polymorphism is based solely on the overall types of the super-class and any sub-classes thereof. Those types are usually related such that sub-classes can be cast to their super-class(es). Traditional polymorphism is therefore contingent on the destination type being predefined to allow casting from a particular source type.
Accordingly, there is a need for a polymorphism paradigm for objects that provides increased predictability, flexibility, and/or versatility.